
import static java.lang.Math.*;
//import java.util.*
//通配符，可以充当任何类
//不是导入所有类，使用到哪个类就帮忙导哪个类

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-03-17
 * Time: 18:41
 */
class Student{
//    public String name;
//    public int age;

//    public String name = "dm";
//    public  int age = 10;
    //就地初始化

    //成员变量在没有初始化是默认值
    //引用类型：null
    //int ：0
    //float：0.0f
    //char：'\u0000'
    private String name;
    private int age;
    //只能在当前类当中使用
    public static String classroom = "301";
    //存储在方法区

    public void doClass(){
        System.out.println(this.name + "shangke");
        this.print();
    }
    public Student(){
//        this.name = "daming";
//        this.age = 18;

//        this("daming",18);
        //只能在构造方法里才能用
        //构造方法调用构造方法
        //不可自己调用自己
        //只能放在构造方法的第一行

        //System.out.println("meiyou");
        //this("daming",18);
        //error

        //会帮助初始化
        System.out.println("meiyou");
    }


    public Student(String name, int age) {
        //this();
        this.name = name;
        this.age = age;
        System.out.println("dai");
    }

    public void print() {
        System.out.println(this.name+" "+this.age);
        //func();
    }

    public String getName() {
        return this.name;
    }
    public int getAge() {
        return this.age;
    }
    public void setName(String name) {
        this.name = name;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public static void func(){
        System.out.println("154");
    }//类方法，不依赖对象

}
public class Test {

    public static void func2() {

    }
    public  void func1() {

    }
    public static void main(String[] args) {

        Test test = new Test();
        test.func1();
        func2();
        Student.func();
        //静态方法的内部，不能调用非静态方法，因为静态方法不依赖对象，但是非静态方法依赖对象
    }
    public static void main5(String[] args) {
        Student student1 = new Student("xusheng1",15);
        Student student2 = new Student("xusheng2",15);
        Student student3 = new Student("xusheng3",15);
        System.out.println("classroom" + Student.classroom);
        //类的静态成员变量，通过类名访问，说明静态成员变量不属于对象，由所有对象共享

        student1 = student3;
        //引用只能指向对象
        //student1这个引用指向了student2这个引用指向的对象
        //非引用指向引用

        Student student4 = null;
        System.out.println(student4.classroom);
        //classroom不属于对象，不在对象里，不会引发空指针异常


    }
    public static void main4(String[] args) {
        Student student = new Student();
        student.setName("gujingjing");
        student.setAge(19);
        student.print();
    }
    public static void main3(String[] args) {
        String name = "ajs";
        double d = 19.9;
        double f = 6.2;
        double m = sqrt(d);
        int[] arr={1,2,3};
        Arrays.sort(arr);
        System.out.println(m);
    }
    public static void main1(String[] args) {
        Student student = new Student();
        student.print();
        Student student1 = null;//不指向任何对象
    }
    public static void main2(String[] args){
        Student student = new Student();
        student.setName("daming");
        student.setAge(15);
        System.out.println(student.getName());
        System.out.println(student.getAge());
        //Student student1 = new Student("daming",15);
    }
}
